package MapDemo.demo1;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

public class test {
    public static void main(String[] args){
        // 创建Map集合的对象
        Map<String,String> m = new HashMap<>();
        // 获取Map集合的键集合
        Set<String> s = m.keySet();
        // 添加元素
        m.put("马车", "看见我的枪了吗？");
        m.put("曹操","不可能绝对不可能");
        System.out.println(m.containsValue("不可能绝对不可能"));
        System.out.println(m.size());
        // 获取Map集合的键值对集合
        Set<Map.Entry<String,String>> entries = m.entrySet();
        for (Entry<String,String> entries2 : entries) {
            String key = entries2.getKey();
            String value = entries2.getValue();
            System.out.println(key +  "==" + value);
        }
        System.out.println("----迭代器---");
        Iterator<Map.Entry<String,String>> it = entries.iterator();
        // 遍历迭代器
        while (it.hasNext()){
            Map.Entry<String,String> me = it.next();
            String key = me.getKey();
            String value = me.getValue();
            System.out.println(key + value);
        }
        System.out.println("lambda表达式");
        entries.forEach(entries2 -> {
            System.out.println(entries2.getKey() + entries2.getValue());
        });
        m.clear();
        System.out.println(m.isEmpty());
    }
}
